-- attack_cure
-- created by zhuangsl
-- 攻击时，概率回复a~b生命

return {
    apply = function(prop, baseValue)
        return baseValue + prop[3];
    end,

    -- 进入下一层触发
    trigger = function(who, prop, arg)
        -- 概率触发
        local rand1 = DungeonM.getRandSeed("attack_cure")%1000;
        if rand1 > prop[3] then
            return
        end

        local range = string.explode(prop[2], "~");
        local min, max;

        if #range > 1 then
            min = tonumber(range[1]);
            max = tonumber(range[2]);
        else
            min = tonumber(range[1]);
            max = min;
        end

        assert(max >= min);

        local differ = max - min;
        local rand2 = DungeonM.getRandSeed("attack_cure");
        local value = min + rand2 % (differ + 1);

        BonusM.doBonus({ 2, "hp", value, }, "prop_attack_cure");

        return true;
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;
        local rate = math.modf(prop[3] / 10);

        desc = string.gsub(desc, "{0}", prop[2]);

        desc = string.gsub(desc, "{1}", rate);

        desc = string.gsub(desc, "~", getLocStr("hyphen"));

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};
